import * as api from '../../api/common';

Page({
  data: {
    userInfo: {}
  },
  onLoad: function (options) {
    const userInfo = tt.getStorageSync('info');
    if (userInfo && userInfo.id) {
      this.memberInfo(userInfo.id);
    } else {
      tt.showToast({
        title: '用户信息获取失败',
        icon: 'fail'
      });
      return;
    }
  },
  onShow: function () {
    const userInfo = tt.getStorageSync('info');
    if (userInfo && userInfo.id) {
      this.memberInfo(userInfo.id);
    } else {
      tt.showToast({
        title: '用户信息获取失败',
        icon: 'fail'
      });
      return;
    }
  },
  async memberInfo(id) {
    try {
      const {
        data
      } = await api.memberInfo({
        id: id
      });
      const baseUrl = api.baseUrl + '/';
      if (data.avatar) {
        data.avatar = baseUrl + data.avatar
      }
      this.setData({
        userInfo: data
      })
    }  catch (error) {
      console.error('获取票据详情失败', error);
    }
  },
  goLogin() {
    // if (!checkLogin()) {
    //   this.selectComponent('#loginHandler').showDialog();
    // }
  },
  toUserInfo(){
    tt.navigateTo({
      url: '../userInfo/index',
      success: (res) => {},
      fail: (res) => {},
    });
  },
  toTicket(){
    tt.navigateTo({
      url: '../ticket/index',
      success: (res) => {},
      fail: (res) => {},
    });
  },
  toOrder(){
    tt.navigateTo({
      url: '../order/index',
      success: (res) => {},
      fail: (res) => {},
    });
  },
  toPoint(){
    tt.navigateTo({
      url: '../points/index',
      success: (res) => {
        
      },
      fail: (res) => {
        
      },
    });
  },
  toAudience(){
    tt.navigateTo({
      url: '../audience/index',
      success: (res) => {
        
      },
      fail: (res) => {
        
      },
    });
  }
})